<template>
    <div class="service">
        <div class="service-item">
            <div style="height: 55px"></div>
            <div style="height: 100px; width: 40px;margin:auto'background:red"></div>
            <div class="teltPhoneImg">
                <img src="@/assets/svg/tubusi_w_index_right_tel.svg" />
            </div>
        </div>
        <div class="service-back" v-if="showButton" @click="scrollToTop">
            <img src="@/assets/svg/tubusi_w_index_right_top.svg" />
        </div>
    </div>
</template>

<script setup>
const isAtTop = ref(true);
const showButton = ref(false);

// 设置滚动距离显示回到顶部按钮
const checkScroll = () => {
    isAtTop.value = window.scrollY <= 300;
    showButton.value = !isAtTop.value;
};

onMounted(() => {
    window.addEventListener("scroll", checkScroll);
});

onBeforeUnmount(() => {
    window.removeEventListener("scroll", checkScroll);
});
const scrollToTop = () => {
    window.scrollTo({
        top: 0,
        behavior: "smooth",
    });
};
</script>

<style lang="less" scoped>
.service {
    position: fixed;
    bottom: 20px;
    right: 20px;
    // z-index: 11;
    width: 60px;

    .service-item {
        width: 60px;
        height: 206px;
        background: var(--green);
        box-shadow: 0px 10px 20px 0px var(--shadow);
        border-radius: 30px;
        border: 1px solid var(--white);
        margin-bottom: 16px;
        .teltPhoneImg {
            display: flex;
            align-items: center;
            justify-content: center;
            img {
                width: 30px;
                height: 30px;
            }
        }
    }
    .service-back {
        width: 60px;
        height: 60px;
        background: var(--white);
        box-shadow: 0px 10px 20px 0px var(--shadow);
        border: 1px solid var(--white);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
            width: 30px;
            height: 30px;
        }
    }
}
</style>
